import { Component, screen, view } from "cc";
import * as fgui from "fairygui-cc";
import Instance from "../Utils/Instance";
import  WindowManager  from "../../Game/module/window/WindowManager";
import { ExternalGLoader } from "../Res/ExternalGLoader";
/**层级管理器 */
export class LayerManager {
    private _world: fgui.GComponent;
    private _ui: fgui.GComponent;
    private _map: fgui.GComponent;
    private _mapObjects: fgui.GComponent;
    private _worldEffect: fgui.GComponent;
    private _mainUIDown: fgui.GComponent;
    private _mainUI: fgui.GComponent;
    private _sceneUI: fgui.GComponent;
    private _sceneUiUp: fgui.GComponent;
    private _damage: fgui.GComponent;
    private _viewUI: fgui.GComponent;
    private _window: fgui.GComponent;
    private _guide: fgui.GComponent;
    private _tip: fgui.GComponent;
    private _notice: fgui.GComponent;
    private _loading: fgui.GComponent;
    private _gameAni: fgui.GComponent;
    public static get ins(): LayerManager {
        return Instance.get(LayerManager);
    }
    public get gameAni(): fgui.GComponent {
        return this._gameAni;
    }
    public get loading(): fgui.GComponent {
        return this._loading;
    }
    public get notice(): fgui.GComponent {
        return this._notice;
    }
    public get tip(): fgui.GComponent {
        return this._tip;
    }
    public get guide(): fgui.GComponent {
        return this._guide;
    }
    public get window(): fgui.GComponent {
        return this._window;
    }
    public get viewUI(): fgui.GComponent {
        return this._viewUI;
    }
    public get damage(): fgui.GComponent {
        return this._damage;
    }
    public get sceneUiUp(): fgui.GComponent {
        return this._sceneUiUp;
    }
    public get sceneUI(): fgui.GComponent {
        return this._sceneUI;
    }
    public get mainUI(): fgui.GComponent {
        return this._mainUI;
    }
    public get mainUIDown(): fgui.GComponent {
        return this._mainUIDown;
    }
    public get worldEffect(): fgui.GComponent {
        return this._worldEffect;
    }
    public get mapObjects(): fgui.GComponent {
        return this._mapObjects;
    }
    public get map(): fgui.GComponent {
        return this._map;
    }
    public get ui(): fgui.GComponent {
        return this._ui;
    }
    public get world(): fgui.GComponent {
        return this._world;
    }
    public init(): void {
        fgui.GRoot.create();
        // fgui.UIObjectFactory.setLoaderExtension(ExternalGLoader);
        // 根容器
        this._world = new fgui.GComponent();
        this._ui = new fgui.GComponent();
        fgui.GRoot.inst.addChild(this._world);

        // 场景容器
        this._map = new fgui.GComponent();
        this._mapObjects = new fgui.GComponent();
        this._world.addChild(this._map);
        this._world.addChild(this._mapObjects);

        // ui容器
        fgui.GRoot.inst.addChild(this._ui);

        this._worldEffect = new fgui.GComponent();
        this._mainUIDown = new fgui.GComponent();
        this._mainUI = new fgui.GComponent();
        this._sceneUI = new fgui.GComponent();
        this._sceneUiUp = new fgui.GComponent();
        this._damage = new fgui.GComponent();
        this._damage.touchable = false;
        this._viewUI = new fgui.GComponent();
        this._window = new fgui.GComponent();
        this._guide = new fgui.GComponent();
        this._tip = new fgui.GComponent();
        this._notice = new fgui.GComponent();
        this._loading = new fgui.GComponent();
        this._gameAni = new fgui.GComponent();

        fgui.GRoot.inst.addChild(this._worldEffect);
        this._worldEffect.touchable = false;
        fgui.GRoot.inst.addChild(this._mainUIDown);
        fgui.GRoot.inst.addChild(this._mainUI);
        fgui.GRoot.inst.addChild(this._sceneUI);
        fgui.GRoot.inst.addChild(this._sceneUiUp);
        fgui.GRoot.inst.addChild(this._viewUI);
        fgui.GRoot.inst.addChild(this._window);
        fgui.GRoot.inst.addChild(this._guide);
        // this._guide.touchable = false;
        fgui.GRoot.inst.addChild(this._tip);
        fgui.GRoot.inst.addChild(this._notice);
        fgui.GRoot.inst.addChild(this._loading);
        // this._loading.touchable = false;
        fgui.GRoot.inst.addChild(this._gameAni);
        WindowManager.ins.init();
        WindowManager.ins.initRoot(this._window);
        screen.on("window-resize", this.onResize, this);
        this.onResize();
        this._window.makeFullScreen();
    }
    private onResize(): void {
        const screenWidth: number = view.getVisibleSize().width;
        const screenHeight: number = view.getVisibleSize().height;
        this._worldEffect.setSize(screenWidth, screenHeight);
        this._mainUIDown.setSize(screenWidth, screenHeight);
        this._mainUI.setSize(screenWidth, screenHeight);
        this._sceneUI.setSize(screenWidth, screenHeight);
        this._sceneUiUp.setSize(screenWidth, screenHeight);
        this._viewUI.setSize(screenWidth, screenHeight);
        this._window.setSize(screenWidth, screenHeight);
        this._guide.setSize(screenWidth, screenHeight);
        this._tip.setSize(screenWidth, screenHeight);
        this._notice.setSize(screenWidth, screenHeight);
        this._loading.setSize(screenWidth, screenHeight);
    }
}